package com.lsa.letcode.the91.decodeWays;

import java.util.Arrays;

public class Main {
	private static int ONE = 1;
	private static int ZERO = 0;
	
	public static void main(String[] args) {
		int[] arr = new int[5];
		Arrays.fill(arr, ZERO);
		int cnt = 0;
		do{
			System.out.println(Arrays.toString(arr));
			cnt++;
		}
		while(next(arr));
		
		System.out.println(String.format("cnt=%s", cnt));
	}
	
	static boolean next(int[] arr) {
		boolean hasNext = false; 
		for (int i = arr.length - 1; i > -1; i--) {
			if (i > 0 &&  i < arr.length - 1) {
				if (arr[i - 1] == ZERO && arr[i] == ZERO && arr[i + 1] == ONE) {
					arr[i] = ONE;
					for (int j = i + 1; j < arr.length; j++) {
						arr[j] = ZERO;
					}
					hasNext = true;
					break;
				}
			}
			else if (i == arr.length - 1){
				if (arr[i - 1] == ZERO && arr[i] == ZERO) {
					arr[i] = ONE;
					hasNext = true;
					break;
				}
			}
			else {
				if (arr[i] == ZERO) {
					arr[i] = ONE;
					for (int j = i + 1; j < arr.length; j++) {
						arr[j] = ZERO;
					}
					hasNext = true;
					break;
				}
			}
		}
		
		return hasNext;
	}
	
	/*
	 0 0 0 0
	 0 0 0 1
	 0 0 1 0
	 0 1 0 0
	 0 1 0 1
	 1 0 0 0
	 1 0 0 1
	 
	[0, 0, 0, 0]
	[0, 0, 0, 1]
	[0, 0, 1, 0]
	[0, 1, 0, 0]
	[0, 1, 0, 1]
	[1, 0, 0, 0]
	[1, 0, 0, 1]
	[1, 0, 1, 0]
	 
	 0 0 0 0 0
	 0 0 0 0 1
	 0 0 0 1 0
	 0 0 1 0 0
	 0 0 1 0 1
	 0 1 0 0 0
	 0 1 0 0 1
	 1 0 0 0 0
	 1 0 0 0 1
	 1 0 0 1 0
	 1 0 1 0 0  
	 1 0 1 0 1
	 
	 [0, 0, 0, 0, 0]
	 [0, 0, 0, 0, 1]
	 [0, 0, 0, 1, 0]
	 [0, 0, 1, 0, 0]
	 [0, 0, 1, 0, 1]
	 [0, 1, 0, 0, 0]
	 [0, 1, 0, 0, 1]
	 [0, 1, 0, 1, 0]
	 [1, 0, 0, 0, 0]
	 [1, 0, 0, 0, 1]
	 [1, 0, 0, 1, 0]
	 [1, 0, 1, 0, 0]
	 [1, 0, 1, 0, 1]
	 
	 * */
}
